package springmvcdemo.controller;

import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;
import springmvcdemo.model.Student;

import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@RequestMapping("/con3")
@RestController
public class Controller3 {
    //1.接受数组
    @RequestMapping("/test1")
    public String test1(String[] params) {
        return "接收到的参数："+ Arrays.toString(params);
    }
    //2.传递集合
    @RequestMapping("/test2")
    public String test2(@RequestParam("ListParam")List<String> ListParam) {
        return "接收到的参数是："+ListParam;
    }
    //3.传递json
    @RequestMapping("/test3")
    public String test3(@RequestBody Student student) {
        return "接收到的参数是："+student;
    }

    //4.获取url
    @RequestMapping("/test4/{name}")
    public String test4(@PathVariable("name") String name) {
        return "接收到的参数是："+name;
    }

    @RequestMapping("/test5/{name}/{age}")
    public String test5(@PathVariable("name") String name,@PathVariable("age") Integer age) {
        return "接收到的参数是："+name+" "+age;
    }
    //5.上传文件
    @RequestMapping("/test6")
    public String test6( @RequestPart("file666") MultipartFile file) throws IOException {
        System.out.println("1:"+file.getName());
//        System.out.println("2"+file.getContentType());
//        System.out.println("3"+file.getOriginalFilename());
        //将该文件上传到什么位置
        //file.transferTo(new File("D:\\"+file.getName()));


        return "4接收到的参数是："+file;
    }




}
